package com.maket.scxx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.maket.scxx.domain.GcFactoryUnitTable;
import com.maket.scxx.domain.TeamMembers;
import com.maket.scxx.feign.GetCodeFeign;
import com.maket.scxx.service.TeamMembersService;
import com.maket.scxx.utils.getCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.maket.scxx.domain.BzTeamSchedule;
import com.maket.scxx.service.IBzTeamScheduleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产班组Controller
 * 
 * @author ruoyi
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/bzTeam")
public class BzTeamScheduleController extends BaseController
{
    @Autowired
    private IBzTeamScheduleService bzTeamScheduleService;
    @Autowired
    private TeamMembersService teamMembersService;

    /**
     * 查询生产班组列表
     */
    @RequiresPermissions("scxx:bzTeam:list")
    @GetMapping("/list")
    public TableDataInfo list(BzTeamSchedule bzTeamSchedule)
    {
        startPage();
        List<BzTeamSchedule> list = bzTeamScheduleService.selectBzTeamScheduleList(bzTeamSchedule);
        return getDataTable(list);
    }

    /**
     * 导出生产班组列表
     */
    @RequiresPermissions("scxx:bzTeam:export")
    @Log(title = "生产班组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BzTeamSchedule bzTeamSchedule)
    {
        List<BzTeamSchedule> list = bzTeamScheduleService.selectBzTeamScheduleList(bzTeamSchedule);
        ExcelUtil<BzTeamSchedule> util = new ExcelUtil<BzTeamSchedule>(BzTeamSchedule.class);
        util.exportExcel(response, list, "生产班组数据");
    }

    /**
     * 获取生产班组详细信息
     */

    @RequiresPermissions("scxx:bzTeam:query")
    @GetMapping(value = "/{bzCode}")
    public AjaxResult getInfo(@PathVariable("bzCode") String bzCode)
    {
        List<TeamMembers> teamMembers = teamMembersService.selectWithBzCode(bzCode);
        BzTeamSchedule bzTeamSchedule = bzTeamScheduleService.selectBzTeamScheduleByBzCode(bzCode);
        bzTeamSchedule.setPeoples(teamMembers);
        return success(bzTeamSchedule);
    }

    /**
     * 新增生产班组
     */

    @RequiresPermissions("scxx:bzTeam:add")
    @Log(title = "生产班组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BzTeamSchedule bzTeamSchedule)
    {
        return toAjax(bzTeamScheduleService.insertBzTeamSchedule(bzTeamSchedule));
//        return toAjax(1);
    }

    /**
     * 修改生产班组
     */
    @RequiresPermissions("scxx:bzTeam:edit")
    @Log(title = "生产班组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BzTeamSchedule bzTeamSchedule)
    {
        return toAjax(bzTeamScheduleService.updateBzTeamSchedule(bzTeamSchedule));
    }

    /**
     * 删除生产班组
     */
    @RequiresPermissions("scxx:bzTeam:remove")
    @Log(title = "生产班组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bzCodes}")
    public AjaxResult remove(@PathVariable String[] bzCodes)
    {
        return toAjax(bzTeamScheduleService.deleteBzTeamScheduleByBzCodes(bzCodes));
    }

    /**
     * 查询生产班组列表
     */
    @RequiresPermissions("scxx:bzTeam:list")
    @GetMapping("/listScdy")
    public TableDataInfo list(GcFactoryUnitTable gcFactoryUnitTable)
    {
        startPage();
        List<GcFactoryUnitTable> list = bzTeamScheduleService.getAllScdy(gcFactoryUnitTable);
        return getDataTable(list);
    }
}
